package com.ygqh.baby.service;

import com.ygqh.baby.ao.*;
import com.ygqh.baby.model.CardCouponAction;
import com.ygqh.baby.model.CardCouponReceiver;
import com.ygqh.baby.model.YgCardCouponInfo;
import com.ygqh.baby.model.YgSkuInfo;
import com.ygqh.baby.po.*;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

public interface YgCardCouponDetailService {

	List<YgCardCouponDetail> find();

	int findCount();

	YgCardCouponDetail findById(Long id);

	YgCardCouponDetail findById(Long id, Long userId);

	int deleteSoft(Long[] ids);

	int deleteSoft(Long id);

	int save(YgCardCouponDetail ygCardCouponDetail);

	int update(YgCardCouponDetail ygCardCouponDetail);

	int saveOrUpdate(YgCardCouponDetail ygCardCouponDetail);

	ResultSet<YgCardCouponDetail> search(QueryInfo queryInfo, CardType cardType, CardMode cardMode, Date startDate, Date endDate, String q);

	List<YgCardCouponInfo> findCardInfoByUserId(Long userId, UseStatus useStatus);

	YgCardCouponInfo findCardInfo(Long cardDetailId, Long userId);

	int saveCardCouponDetail(Long userId, YgCardCoupon cardCoupon, Long paymentCode, String remark);

	Message generateCardCouponBatch(Long userId, String cardIds, Long paymentCode, String remark);

	Message generateCardCoupon(Long userId, Long cardId, Long paymentCode, String remark);

	Message generateCardCoupon(Long userId, YgCardCoupon cardCoupon, Long paymentCode, String remark, String sourceCode);

	/**
	 * 兑换卡券
	 *
	 * @param cardDetailId
	 * @param userId
	 * @param address
	 * @return
	 */
	Message cashCard(Long cardDetailId, Long userId, YgUserAddress address);

	/**
	 * 根据卡券信息保存订单
	 *
	 * @param userId      用户id
	 * @param paymentCode 订单编号
	 * @param addressInfo 收件人地址信息
	 * @param skuInfo     sku信息
	 * @param dataStatus  订单数据状态
	 * @param parentId    父级订单编号
	 * @param reduceStock 是否扣减库存
	 * @param sourceCode  订单来源
	 * @param skuInfo     商品信息
	 * @return
	 */
	YgOrder saveGoodsCardOrder(Long userId, Long paymentCode, YgUserAddress addressInfo, DataStatus dataStatus, Long parentId, boolean reduceStock, String sourceCode,
							   YgSkuInfo... skuInfo);

	int updateRelationId(Long cardDetailId, Long relationId);

	Message shareCard(Long cardId, Long userId, String formId);

	Message receiveCard(Long cardId, Long sharer, Long receiver);

	Boolean isReceived(CardType cardType, Long userId);

	YgCardCouponInfo findCardInfoByDetailId(Long cardDetailId);

	YgCardCouponDetail findByUserIdAndRelationId(Long userId, Long relationId);

	/**
	 * 获取卡券明细集
	 *
	 * @param userId      指定用户id
	 * @param cardId      指定卡券id
	 * @param useStatus   卡券明细使用状态
	 * @param startDate   限制开始时间
	 * @param endDate     限制结束时间
	 * @param overdueDate 卡券明细过期时间
	 * @param types       卡券类型
	 * @return
	 */
	List<YgCardCouponDetail> findCardCouponList(Long userId, Long cardId, UseStatus useStatus, String startDate, String endDate, String overdueDate, CardType... types);

	List<YgCardCouponDetail> findCardCouponList(UseStatus useStatus, String startDate, String endDate, CardType... types);

	/**
	 * 获取未使用卡券 默认过滤掉分享红包生成的单次包邮卡
	 *
	 * @return
	 */
	List<YgCardCouponDetail> findByUnUsedCardCoupon();

	/**
	 * 根据订单id生成卡券
	 *
	 * @param orderId
	 * @param count
	 * @param remark
	 * @param userId
	 * @return
	 */
	Message generateCardWithOrderId(Long orderId, Long count, String remark, Long userId);

	/**
	 * 更新卡券关联订单的sku
	 *
	 * @param cardId
	 * @param changeSkuInfo sku更换信息，例：[{"sourceSkuId":434512,"skuId":434513}]
	 * @param userId
	 * @return
	 */
	Message changeCardCouponRelationOrder(Long cardId, String changeSkuInfo, Long userId);

	/**
	 * 根据特定备注和指定状态查询
	 *
	 * @param userId
	 * @param remark
	 * @param status
	 * @return
	 */
	List<YgCardCouponDetail> findByRemark(Long userId, String remark, DataStatus status);

	int transferCardCoupon(Long sourceUserId, Long targetUserId);

	/**
	 * 获取领取用户信息集
	 *
	 * @param cardDetailId
	 * @return
	 */
	List<CardCouponReceiver> findReceiverListByCardId(Long cardDetailId);

	/**
	 * 返还卡券（仅限包邮卡）
	 *
	 * @param userId
	 * @param relationId
	 * @return
	 */
	int returnExpressCard(Long userId, Long relationId);

	/**
	 * 主要应用于卡券订单退款，卡券失效
	 *
	 * @param orderIdList
	 * @return
	 */
	int deleteByRelationId(List<Long> orderIdList);

	/**
	 * 获取用户领取的指定卡券
	 *
	 * @param cardId
	 * @param userId
	 * @return
	 */
	List<YgCardCouponInfo> findByCardIdAndUserId(Long cardId, Long userId);

	/**
	 * 指定卡券领取记录
	 *
	 * @param cardId     卡券id
	 * @param sourceCode 来源用户
	 * @return
	 */
	List<YgUser> findReceiveUserListBySource(Long cardId, String sourceCode);

	/**
	 * 卡券运费支付成功回调处理
	 *
	 * @param userId
	 * @param cardDetailId
	 * @param orderId
	 * @param totalPrice
	 * @param appType
	 * @param payType
	 * @param address
	 */
	Message cashCardByPayExpress(Long userId, Long cardDetailId, Long orderId, BigDecimal totalPrice, AppType appType, PayType payType, YgUserAddress address);

	/**
	 * 给新注册用户发拉新活动卡券
	 *
	 * @param userId
	 */
	void asyncGivePullNewCard(Long userId);

	/**
	 * 根据指定SKU生成卡券
	 *
	 * @param skuCode  SKU编码
	 * @param userId   用户id
	 * @param cardType 卡券类型
	 * @param remark   备注
	 * @param remark   卡券金额
	 * @return
	 */
	void generateCardCouponDetailBySku(String skuCode, Long userId, CardType cardType, String remark, BigDecimal cardPrice);

	/**
	 * 领取卡券活动
	 *
	 * @param userId     用户id
	 * @param actionInfo 活动信息
	 * @return
	 */
	Message receiveCardCouponAction(Long userId, CardCouponAction actionInfo);
}
